package TwoPointers;

public class _3_LongestSubstringWithoutRepeatingCharacters {
    public int lengthOfLongestSubstring(String s) {
        if(s==null || s.length()==0) return 0;
        int mlength = 0;
        int[] chas = new int[128];
        int left = 0;
        for (int i = 0; i < s.length(); i++) {
            int pos = '~' - s.charAt(i);
            chas[pos]++;
            while (left < i && chas[pos] > 1) {
                chas['~' - s.charAt(left++)]--;
            }
            mlength = Math.max(mlength, i - left + 1);
        }
        return mlength;
    }
}
